// pages/auth/auth.js
import { login } from '../../utils/asyncWx.js'
import  regeneratorRuntime from '../../lib/runtime/runtime.js'
import { require } from '../../require/index.js'

Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  async handleGetUserInfo(e){
    try {
      const {rawData, signature, iv, encryptedData} = e.detail
      const code = await login()
      const params = { rawData, signature, iv, encryptedData, code}
      console.log(code)
      const token = await require({url: '/users/wxlogin', data: params, method: 'post'})||'eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI1ODQxIiwiYXV0aCI6IlJPTEVfVVNFUiIsImV4cCI6MTU4Njk4NjM0OX0.uyAbC0rZgzvBHPt5H2bcr6Yio5Ni6LXUw4c69O5xfpcB06Q1Ae6H-GJDGFs0VhsBEPkNvDYDTuzBpHGK-W2jJQ'
      // 没企业openid 拿不到呢
      wx.setStorageSync('token', token)
      wx.navigateBack({
        delta: 1
      });
    } catch (error) {
      console.log(error)
    }
  }
})